package cn.yqx.bankshop.order.controller;

import cn.yqx.bankshop.order.page.PageRequest;
import cn.yqx.bankshop.order.page.PageResult;
import cn.yqx.bankshop.order.pojo.BuSupplierStore;
import cn.yqx.bankshop.order.service.SupplierStoreService;
import cn.yqx.bankshop.result.Result;
import cn.yqx.bankshop.result.ResultCode;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@Slf4j
@RestController
@RequestMapping("/api/v1/supplierStore")
public class SupplierStoreController {
    @Autowired
    SupplierStoreService storeService ;
    private static final String PAGE_REQUEST_KEY = "pageRequest" ;
    private static final String PARAMETER_KEY = "parameter" ;

    @RequestMapping(value = "get_all_supplierStore",method = RequestMethod.POST)
    public Object getAllSupplierStore(@RequestBody JSONObject json ){
        Result result ;
        try {
            result = Result.success() ;
            PageRequest pageRequest = JSON.parseObject(json.getJSONObject(PAGE_REQUEST_KEY).toJSONString(), PageRequest.class) ;
            JSONObject parameter = json.getJSONObject(PARAMETER_KEY) ;

            PageResult pageResult = storeService.getAllSupplierStore(pageRequest,parameter) ;
            result.setData(pageResult);
        }catch (Exception e){
            result = Result.failed(ResultCode.SYSTEM_EXECUTION_ERROR) ;
            log.info("error : {} " , e);
        }
        return result ;
    }
}
